#include<iostream>
#include<string>
#include<unordered_map>
using std::string;
using std::unordered_map;


class Solution {
public:
    string minWindow(string s, string t) {
        unordered_map<char, int> map;
        for (auto c: t) {
            if (map.find(c) == map.end()) map[c] = 1;
            else map[c]++;
        }
        //for (auto& k: map) std::cout << "(" << k.first << "," << k.second << ")" << "\n";
        // 初始化
        int validNum = map.size(), p0 = 0, bestP0 = 0, L = 0;
        while (map.find(s[p0]) == map.end() && p0 < s.size()) p0++;  // 找到在t中的项
        auto p1 = p0;
        while (p1 < s.size()) {
            // 先寻找p1使得validNum = 0
            while (validNum > 0 && p1 < s.size()) {
                if (map.find(s[p1]) != map.end()) {
                    validNum = (map[s[p1]] == 1) ? validNum-1 : validNum;
                    map[s[p1]] --;
                }
                p1 ++;
            }
            // 寻找p0使得子串长度尽可能小
            
            while (validNum == 0 && p0 <= p1 - t.size()) {
                // 看当前p0位置能否舍去
                if (map.find(s[p0]) == map.end()) p0++;
                else if(map[s[p0]] < 0) {
                    map[s[p0]]++;
                    p0++;
                }
                else break;
            }
            // 记录最佳结果
            if (validNum == 0 && (L == 0 || p1-p0 < L)) {
                bestP0 = p0;
                L = p1-p0;
            }
            // 移动p0并开启下一个滑动窗
            
            if (map.find(s[p0]) != map.end()) {
                validNum = (map[s[p0]] == 0) ? validNum+1 : validNum;
                map[s[p0]] ++;
            }
            p0++;

        }
        return s.substr(bestP0, L); 
    }

};


int main() {
    string s, t;
    std::getline(std::cin, s);
    std::getline(std::cin, t);
    std::cout << s << "\n" << t << "\n";
    std::cout << Solution().minWindow(s, t) << "\n";
    return 0;
}